package com.house.ujiayigou.thirdpart.weixin;


import com.yunmasoft.service.pay.wexin.WxmpRequestBase;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;

public class JSSDKGetticket extends WxmpRequestBase {
    public static final String KEY_ACCESS_TOKEN = "access_token";
    public static final String URL_API_BASE = "https://api.weixin.qq.com/cgi-bin/ticket/getticket";
    // KEYS
    protected static final List<String> KEYS_PARAM = Arrays.asList(
            "access_token", "type"
    );

    // CONSTRUCT
    public JSSDKGetticket(String accessToken) {
        super(new Properties());

        this.setProperty("type", "jsapi");
        this.setAccessToken(accessToken);

        return;
    }

    public JSSDKGetticket setAccessToken(String accessToken) {
        super.setProperty(KEY_ACCESS_TOKEN, accessToken);

        return (this);
    }

    // BUILD
    @Override
    public JSSDKGetticket build() {
        return (this);
    }

    // TO_URL
    @Override
    public String toURL() {
        throw (
                new UnsupportedOperationException("This request does not execute on client side.")
        );
    }

    // EXECUTE
    @Override
    public JSSDKGetticketResponse execute()
            throws IOException {
        String url = URL_API_BASE + "?" + super.toQueryString(KEYS_PARAM);

        String respJson = super.executeGet(url);

        return (new JSSDKGetticketResponse(respJson));
    }
}
